function [h0_1,h0_2,hx_1,hx_2,sigma,gama0,gamaz,gamax,sigmaz] = unfoldTheta2_threshold_macro(theta2,nx)

% Regime 1
h0_1     = zeros(nx,1);
for i=1:nx
    name = ['h0',num2str(i),'_1'];
    h0_1(i,1) = theta2.(name);
end
hx_1    = zeros(nx,nx);
for i=1:nx
    for j=1:nx
        name = ['hx',num2str(i),num2str(j),'_1'];
        hx_1(i,j) = theta2.(name);
    end
end
if isfield(theta2,'h01_2')
    % Regime 2
    h0_2     = zeros(nx,1);
    for i=1:nx
        name = ['h0',num2str(i),'_2'];
        h0_2(i,1) = theta2.(name);
    end
else
    h0_2 = h0_1;
end
if isfield(theta2,'hx11_2')
    % Regime 2
    hx_2    = zeros(nx,nx);
    for i=1:nx
        for j=1:nx
            try
                name = ['hx',num2str(i),num2str(j),'_2'];
                hx_2(i,j) = theta2.(name);
            catch
                name = ['hx',num2str(i),num2str(j),'_1'];
                hx_2(i,j) = theta2.(name);
            end
        end
    end
else
    hx_2 = hx_1;
end
% Conditional co-variances
sigma = zeros(nx,nx);
for i=1:nx
    for j=1:i
        name = ['sigma',num2str(i),num2str(j)];
        sigma(i,j) = theta2.(name);
    end
end
% Process for z
gama0        = theta2.gama0;
gamaz        = theta2.gamaz;
gamax        = zeros(nx,1);
for i=1:nx
    name = ['gamax',num2str(i)];
    gamax(i,1) = theta2.(name);
end
sigmaz       = theta2.sigmaz;
end

